﻿using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Response;
using YaAppoint.Users;

namespace YaAppoint.Web.Controllers
{
    public class AccountController(ICurrentUserDepartmentAppService currentUserDepartment) : AbpControllerBase
    {
        private readonly ICurrentUserDepartmentAppService _currentUserDepartment = currentUserDepartment;

        [HttpGet("api/account/get-departments")]
        public async Task<IActionResult> GetDepartments(string userName)
        {
            var list = await _currentUserDepartment.GetDepartmentsByUserNameAsync(userName);
            var res = new BackJson()
            {
                code = 0,
                data = list.Select(x => new
                {
                    name = x.Name,
                    id = $"{x.Name}@{x.Id}"
                })
            };
            return new JsonResult(res);
        }
    } 
}
